package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 李旭
 * @date 2021/12/1 11:39
 * @Description:
 *
 * 发消息
 */
@RestController
@RequestMapping("/api/mq")
public class SendMessageController {


    @Autowired
    private RabbitService rabbitService;
    //Spring支持二种
    //发消息
    @GetMapping("/sendMessage/{message}")
    public Result sendMessage(@PathVariable String message){
        rabbitService.sendMessage("exchange520","routingKey520",message);
        return Result.ok();
    }

    //发消息 基于死信的延迟消息
    @GetMapping("/sendDeadLetterMessage/{message}/{ttl}")
    public Result sendDeadLetterMessage(@PathVariable String message,
                                        @PathVariable int ttl){
        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                  DeadLetterMqConfig.routing_dead_1,message,ttl);
        return Result.ok();
    }
    //发消息  基于插件的延迟消息
    @GetMapping("/sendDelayedMessage/{message}/{delayTime}")
    public Result sendDelayedMessage(@PathVariable String message,
                                        @PathVariable int delayTime){
        rabbitService.sendDelayedMessage(DelayedMqConfig.exchange_delay,
                DelayedMqConfig.routing_delay,message,delayTime);
        return Result.ok();
    }
}
